home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / OBJCEDIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  6.6 KB  |  284 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include "XA_DEFS.H"
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "K_DEFS.H"
  15. #include "OBJECTS.H"
  16.  
  17. #if 0
  18. #define CLIP(tree,obj,x,y,w,h)                 \
  19.     object_abs_coords(tree, obj, &x, &y);    \
  20.     w = tree[obj].ob_width;                    \
  21.     h = tree[obj].ob_height;                \
  22.     set_clip(x, y, w, h);
  23. #endif
  24.  
  25. #define CLIP(tree,obj,x,y,w,h)    clear_clip()
  26. #define set_clip(x,y,w,h)        /* We don't want this now! */
  27.  
  28. #if 0
  29. #undef CLIP            /* Those set_clip(..) can't be useful */
  30. #endif
  31.  
  32. /* Johan's versions of these didn't work on my system, so I've redefined them 
  33.    - this is faster anyway */
  34.  
  35. const unsigned char character_type[]={
  36.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  37.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  38.                 CGs,0,0,0,0,0,0,0,0,0,CGw,0,0,0,CGdt,0,
  39.                 CGd,CGd,CGd,CGd,CGd,CGd,CGd,CGd,CGd,CGd,CGp,0,0,0,0,CGw,
  40.                 0,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,
  41.                 CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,CGu|CGa,0,CGp,0,0,CGxp,
  42.                 0,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,
  43.                 CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,CGa,0,0,0,0,0,
  44.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  45.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  46.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  47.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  48.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  49.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  50.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  51.                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  52.  
  53. unsigned long XA_objc_edit(short clnt_pid, AESPB *pb)
  54. {
  55.     OBJECT *form = pb->addrin[0];
  56.     short ed_obj = pb->intin[0];
  57.     short keycode = pb->intin[1];
  58.     TEDINFO *ed_txt;
  59.     char *txt;
  60.     short cursor_pos, o, x, y, w, h;
  61.     int key, tmask, n, chg, update = 0;
  62.  
  63.     ed_txt = (TEDINFO*)form[ed_obj].ob_spec;
  64.     txt = ed_txt->te_ptext;
  65.     cursor_pos = ed_txt->te_tmplen;
  66.  
  67.     pb->intout[0] = 1;
  68.  
  69.     switch(pb->intin[3])
  70.     {
  71.     case 0:
  72.         break;
  73.             
  74.     case 1:            /* ED_INIT - set current edit field */
  75. #if 0                /* For some reason, Johan's version here crashes CAB. Not sure why, so I've put my old version back for now */
  76.         o = 0;
  77.         do {
  78.             form[o].ob_state &= ~IS_EDIT;
  79.         } while(!(form[++o].ob_flags & LASTOB));
  80.             
  81.         form[ed_obj].ob_state |= IS_EDIT;
  82.         ed_txt->te_tmplen = strlen(txt);
  83.         update = 1;
  84. #else
  85.         o=0;
  86.         do{
  87.             form[o].ob_state&=~IS_EDIT;
  88.         } while(!(form[++o].ob_flags&LASTOB));
  89.             
  90.         form[ed_obj].ob_state|=IS_EDIT;
  91.         ((TEDINFO*)form[ed_obj].ob_spec)->te_tmplen=0;
  92.         object_abs_coords(form, ed_obj, &x, &y);
  93.         w=(form+ed_obj)->ob_width;
  94.         h=(form+ed_obj)->ob_height;
  95.         set_clip(x,y,w,h);
  96.                 
  97.         v_hide_c(V_handle);
  98.         draw_object_tree(form,ed_obj,2);
  99.         v_show_c(V_handle,1);
  100.  
  101.         pb->intout[1]=0;
  102.  
  103. #endif
  104.  
  105.         break;
  106.  
  107.     case 2:            /* ED_CHAR - process a character */
  108.         switch(keycode)
  109.         {
  110.         case 0x011b:        /* ESCAPE clears the field */
  111.             txt[0] = '\0';
  112.             ed_txt->te_tmplen = 0;
  113.             update = 1;
  114.             break;
  115.     
  116.         case 0x537f:        /* DEL deletes character under cursor */
  117.             if (txt[cursor_pos])
  118.             {
  119.                 for(x = cursor_pos; x < ed_txt->te_txtlen - 1; x++)
  120.                     txt[x] = txt[x + 1];
  121.                 
  122.                 update = 1;
  123.             }
  124.                     
  125.             break;
  126.                 
  127.         case 0x0e08:        /* BACKSPACE deletes character behind cursor (if any) */
  128.             if (cursor_pos)
  129.             {
  130.                 for(x = cursor_pos; x < ed_txt->te_txtlen; x++)
  131.                     txt[x - 1] = txt[x];
  132.                         
  133.                 ed_txt->te_tmplen--;
  134.         
  135.                 update = 1;
  136.             }
  137.             break;
  138.                     
  139.         case 0x4d00:    /* RIGHT ARROW moves cursor right */
  140.             if ((txt[cursor_pos]) && (cursor_pos < ed_txt->te_txtlen - 1))
  141.             {
  142.                 ed_txt->te_tmplen++;
  143.                 update = 1;
  144.             }
  145.             break;
  146.     
  147.         case 0x4d36:    /* SHIFT+RIGHT ARROW move cursor to far right of current text */
  148.             for(x = 0; txt[x]; x++) ;
  149.  
  150.             if (x != cursor_pos)
  151.             {
  152.                 ed_txt->te_tmplen = x;
  153.                 update = 1;
  154.             }
  155.             break;
  156.                 
  157.         case 0x4b00:    /* LEFT ARROW moves cursor left */
  158.             if (cursor_pos)
  159.             {
  160.                 ed_txt->te_tmplen--;
  161.                 update = 1;
  162.             }
  163.             break;
  164.                 
  165.         case 0x4b34:    /* SHIFT+LEFT ARROW move cursor to start of field */
  166.         case 0x4700:    /* CLR/HOME also moves to far left */
  167.             if (cursor_pos)
  168.             {
  169.                 ed_txt->te_tmplen = 0;
  170.                 update = 1;
  171.             }
  172.             break;
  173.  
  174.         default:        /* Just a plain key - insert character */
  175.             chg = 0;        /* Ugly hack! */
  176.             if (cursor_pos == ed_txt->te_txtlen - 1) {
  177.                 cursor_pos--;
  178.                 ed_txt->te_tmplen--;
  179.                 chg = 1;
  180.             }
  181.                     
  182.             key = keycode & 0xff;
  183.             tmask=character_type[key];
  184.  
  185.             n = strlen(ed_txt->te_pvalid) - 1;
  186.             if (cursor_pos < n)
  187.                 n = cursor_pos;
  188.  
  189.             switch(ed_txt->te_pvalid[n]) {
  190.             case '9':
  191.                 tmask &= CGd;
  192.                 break;
  193.             case 'a':
  194.                 tmask &= CGa|CGs;
  195.                 break;
  196.             case 'n':
  197.                 tmask &= CGa|CGd|CGs;
  198.                 break;
  199.             case 'p':
  200.                 tmask &= CGa|CGd|CGp|CGxp;
  201.                 /*key = toupper((char)key);*/
  202.                 break;
  203.             case 'A':
  204.                 tmask &= CGa|CGs;
  205.                 key = toupper((char)key);
  206.                 break;
  207.             case 'N':
  208.                 tmask &= CGa|CGd|CGs;
  209.                 key = toupper((char)key);
  210.                 break;
  211.             case 'F':
  212.                 tmask &= CGa|CGd|CGp|CGxp|CGw;
  213.                 /*key = toupper((char)key);*/
  214.                 break;
  215.             case 'f':
  216.                 tmask &= CGa|CGd|CGp|CGxp|CGw;
  217.                 /*key = toupper((char)key);*/
  218.                 break;
  219.             case 'P':
  220.                 tmask &= CGa|CGd|CGp|CGxp|CGw;
  221.                 /*key = toupper((char)key);*/
  222.                 break;
  223.             case 'X':
  224.                 tmask = 1;
  225.                 break;
  226.             case 'x':
  227.                 tmask = 1;
  228.                 key = toupper((char)key);
  229.                 break;
  230.             default:
  231.                 tmask = 0;
  232.                 break;            
  233.             }
  234.             
  235.             if (!tmask) {
  236.                 for(n = x = 0; ed_txt->te_ptmplt[n]; n++) {
  237.                        if (ed_txt->te_ptmplt[n] == '_')
  238.                         x++;
  239.                     else if ((ed_txt->te_ptmplt[n] == key)
  240.                         && (x >= cursor_pos))
  241.                         break;
  242.                 }
  243.                 if (key && (ed_txt->te_ptmplt[n] == key)) {
  244.                     for(n = cursor_pos; n < x; n++)
  245.                             txt[n] = ' ';
  246.                     txt[x] = '\0';
  247.                     ed_txt->te_tmplen = x;
  248.                 } else {
  249.                     ed_txt->te_tmplen += chg;        /* Ugly hack! */
  250.                     return XAC_DONE;
  251.                 }
  252.             } else {
  253.                 txt[ed_txt->te_txtlen - 2] = '\0';    /* Needed! */
  254.                 for(x = ed_txt->te_txtlen - 1; x > cursor_pos; x--)
  255.                     txt[x] = txt[x - 1];
  256.  
  257.                 txt[cursor_pos] = (char)key;
  258.     
  259.                 ed_txt->te_tmplen++;
  260.             }
  261.     
  262.             update = 1;
  263.             break;
  264.         }
  265.         pb->intout[1] = ed_txt->te_tmplen;
  266.         break;
  267.             
  268.     case 3:        /* ED_END - turn off the cursor */
  269.         form[ed_obj].ob_state &= ~IS_EDIT;
  270.         update = 1;
  271.         break;
  272.     }
  273.     if (update) {        /* Moved from a number of places above. */
  274.         CLIP(form, ed_obj, x, y, w, h);
  275.         v_hide_c(V_handle);
  276.         draw_object_tree(form, ed_obj, MAX_DEPTH);
  277.         v_show_c(V_handle, 1);
  278.  
  279.         pb->intout[1] = ed_txt->te_tmplen;
  280.     }
  281.     
  282.     return XAC_DONE;
  283. }
  284.